<template>
  <div class="mybox">
    <div class="top_chart">
      <div class="mychart">
        <div class="my-element">
        </div>
        <div class="chart_title">总计</div>
        <div class="chart_value">
          <div class="value">{{ num }}</div>
          <div class="unit">家</div>
        </div>
        <div ref="chart" class="UseWaterBtm"></div>
      </div>
      <div class="right_box">
        <div class="item_box" v-for="(item, index) in typeData" :key="index">
          <div class="bg" :style="{ backgroundColor: color[index] }"></div>
          <div class="my_text">{{ item.school_type }}</div>
          <div class="right_value">
            <div class="left_num">{{ item.school_num }}</div>
            <div class="right_num">{{ item.ratio }}%</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// import chart from './chart.vue'
import { getAction, postAction } from '@/api/manage'
import * as echarts from 'echarts'
export default {
  name: '',
  data () {
    return {
      onebox: '',
      typeData: [],
      pieData: [],
      num: 0,
      color: ['#79D9F9', '#f4eeb8', '#78ffc1', '#fabf04', '#c790f5', '#e73f32', '#a6ce59']
    }
  },
  mounted () {
    this.initData()
  },
  methods: {
    initData () {
      postAction('/topic/data/listAllData/dy_dp_msjc_whjy_xxzyqk', {}).then(res => {
        if (res.success) {
          this.pieData = []
          this.typeData = res.result.data
          res.result.data.map(item => {
            this.num += +item.school_num
            this.pieData.push({ name: item.school_type, value: item.school_num })
          })
          this.initEcahrts(this.pieData)
        }
      })
    },
    initEcahrts (pieData) {
      this.chartInstance = echarts.init(this.$refs.chart)
      let option = {
        color: ['#79D9F9', '#f4eeb8', '#78ffc1', '#fabf04', '#c790f5', '#e73f32', '#a6ce59'],
        tooltip: {
          trigger: 'item',
          textStyle: {
            fontSize: 20
          }
        },
        legend: {
          show: false
        },
        series: [
          {
            type: 'pie',
            radius: ['75%', '90%'],
            center: ['50%', '50%'],
            itemStyle: {
              borderColor: '#132e51',
              borderWidth: 4
            },
            label: {
              show: false
            },
            labelLine: {
              show: false
            },
            tooltip: {
              // valueFormatter: value => `${value}亿元`
              show: false
            },
            data: pieData
          }
        ]
      }

      this.chartInstance.setOption(option)
    }
  }
}
</script>
<style lang="scss" scoped>
.mybox {
  .top_chart {
    display: flex;
    height: 130px;

    .mychart {
      width: 130px;
      height: 130px;
      position: relative;

      .UseWaterBtm {
        width: 130px;
        height: 130px;
      }

      .chart_title {
        font-family: Microsoft YaHei UI;
        font-weight: bold;
        font-size: 12px;
        color: #FFFFFF;
        position: absolute;
        left: 55px;
        top: 40px;
        z-index: 100;
      }

      .chart_value {
        width: 130px;
        display: flex;
        justify-content: center;
        position: absolute;
        left: 0px;
        top: 60px;

        .value {
          font-family: Microsoft YaHei UI;
          font-weight: bold;
          font-size: 20px;
          color: #FFDE00;
        }

        .unit {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 12px;
          color: #AEEDEC;
          margin-top: 5px;
        }
      }

      .my-element {
        width: 130px;
        height: 130px;
        background: url('./img/8.png') no-repeat center center;
        background-size: 100% 100%;
        position: absolute;



        animation: rotate 12s linear infinite;
      }

      @keyframes rotate {
        from {
          transform: rotate(0deg);
        }

        to {
          transform: rotate(360deg);
        }
      }
    }

    .right_box {
      height: 120px;
      padding-top: 5px;
      margin-left: 28px;
      overflow-y: scroll;

      .item_box {
        display: flex;
        margin-bottom: 7px;

        .bg {
          margin-top: 7px;
          width: 4px;
          height: 20px;
          background-color: #79D9F9;

        }

        .my_text {
          width: 60px;
          margin-top: 7px;
          font-family: Microsoft YaHei UI;
          font-weight: 400;
          font-size: 14px;
          color: #FFFFFF;
          margin-left: 9px;
          margin-right: 27px;
        }

        .right_value {
          display: flex;
          justify-content: space-around;
          width: 157px;
          height: 28px;
          background: #1D4276;
          border-radius: 6px;
          opacity: 0.53;

          .left_num {
            font-family: Microsoft YaHei UI;
            font-weight: bold;
            font-size: 18px;
            color: #79D9F9;
          }

          .right_num {
            font-family: Microsoft YaHei UI;
            font-weight: bold;
            font-size: 18px;
            color: #FFFFFF;
          }
        }
      }

    }
  }
}
</style>
